package com.ssm.controller;

import com.ssm.entity.ElcInfotype;
import com.ssm.entity.SysRole;
import com.ssm.entity.SysUser;
import com.ssm.service.ElcInfotypeService;
import com.ssm.service.SysPerService;
import com.ssm.service.SysRoleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class PageController {

    @Resource
    private SysRoleService sysRoleService;
    @Resource
    private SysPerService sysPerService;
    @Resource
    private ElcInfotypeService elcInfotypeService;

//    主要背景页面
    @RequestMapping("/showMain")
    public ModelAndView index(HttpServletRequest req){
        HttpSession session = req.getSession();
        SysUser sysUser = (SysUser) session.getAttribute("sysUser");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("perList",sysPerService.queryByUserId(sysUser.getId()));
        modelAndView.setViewName("main");

        return modelAndView;
    }

//    评论管理页面
    @RequestMapping("/showComments")
    public String comment(){
        return "commentsManage";
    }

//    栏目管理页面
    @RequestMapping("/showcolumn")
    public String program(){
        return "/columnManage";
    }

    @RequestMapping("/roleManage")
    public String role(){
        return "roleManage";
    }
    @RequestMapping("/notice")
    public ModelAndView notice(HttpServletRequest req){
        HttpSession session = req.getSession();
        SysUser sysUser = (SysUser) session.getAttribute("sysUser");
        ModelAndView modelAndView = new ModelAndView();
        ElcInfotype elcInfotype = new ElcInfotype();
        elcInfotype.setUser_id(sysUser.getId());
        elcInfotype.setIsEnable(1);
        modelAndView.addObject("columnList",elcInfotypeService.queryAllByUserId(elcInfotype));
        modelAndView.setViewName("notice/notice");
        return modelAndView;
    }
    @RequestMapping("/addNoticeView")
    public ModelAndView addNoticeView(HttpServletRequest req){
        HttpSession session = req.getSession();
        SysUser sysUser = (SysUser) session.getAttribute("sysUser");
        ModelAndView modelAndView = new ModelAndView();
        ElcInfotype elcInfotype = new ElcInfotype();
        elcInfotype.setUser_id(sysUser.getId());
        elcInfotype.setIsEnable(1);
        modelAndView.addObject("columnList",elcInfotypeService.queryAllByUserId(elcInfotype));
        modelAndView.setViewName("notice/addNotice");
        return modelAndView;
    }
    @RequestMapping("/showList")
    public ModelAndView list(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("roleList",sysRoleService.queryAll(new SysRole()));
        modelAndView.addObject("columnList",elcInfotypeService.queryAll(new ElcInfotype()));
        modelAndView.setViewName("list");
        return modelAndView;
    }
    @RequestMapping("/showHome")
    public String home(){
        return "home";
    }

    }
